﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework;
using Aim2.Weapon.Projectile;

namespace Aim2.Weapon {
    class SpikeGun : Weapon {
        static Texture2D spriteTexture;

        public SpikeGun(Player owner)
            : base(owner) {
                fireDelay = 0.2f;

            frames = 6;
            framesPerSec = 18;
            Scale = 1.0f;
            Depth = 1f;
            speed = 10f;

            this.owner = owner;

            animatedSprite = new AnimatedSprite(this, frames, framesPerSec, false, true);
        }

        public override void Load(ContentManager Content, Viewport viewport) {
            spriteTexture = Content.Load<Texture2D>("Textures/3x2_laserOut");
            spriteTexture.Name = "Textures/3x2_laserOut";
        }

        protected override void CreateProjectiles(Vector2 direction, Side side) {
            Vector2 starting = Owner.Position;
            int offset = Owner.HitBox.Height / 2;
            starting.Y -= offset;
            Spike projectile1 = new Spike(direction, starting, side, owner);
            Spike projectile2 = new Spike(new Vector2(-1, direction.Y), starting, side, owner);
            projectile2.Rotation = (float) (-Math.PI / 4f);
            Spike projectile3 = new Spike(new Vector2(1, direction.Y), starting, side, owner);
            projectile3.Rotation = (float)(Math.PI / 4f);
            fireSoundEffect = "fire_rocket" + Game.Random.Next(1, 3).ToString();

            Owner.Projectiles.Add(projectile1);
            Owner.Projectiles.Add(projectile2);
            Owner.Projectiles.Add(projectile3);
        }

        public override void Update(float elapsed) {
            animatedSprite.UpdateFrame(elapsed);
        }

        public override void Draw(SpriteBatch spriteBatch) {
            Position = Owner.Position;
            int offset = Owner.HitBox.Height / 3;
            position.Y -= offset;
            animatedSprite.DrawFrame(spriteBatch, Position, spriteTexture);

            base.Draw(spriteBatch);
        }
    }
}
